package com.smh.a02test;

import java.util.ArrayList;
import java.util.Objects;

public class Test {
    public static void main(String[] args) {

        ArrayList<Objects> list2 = new ArrayList<>();
        ArrayList<Cat> list = new ArrayList<>();
        list.add(new LIHuaCat("asd",12));
        keepPet(list);
        //keepPet2(list);
        keepPet3(list);
        //keepPet3(list2);


    }
    public static void keepPet(ArrayList<? extends Cat> list){
        for (Cat cat : list) {
            cat.eat();
        }

    }
    public static void keepPet2(ArrayList<? extends Dog> list){
        for (Dog dog : list) {
            dog.eat();
        }

    }
    public static void keepPet3(ArrayList<? extends Animal> list){
        for (Animal animal : list) {
            if (animal instanceof Cat cat){
                cat.eat();
            }
            if (animal instanceof Dog dog){
                dog.eat();
            }
        }

    }
}

